﻿using System;
using System.Collections.Generic;
using IBNet.UtilsDataStructuresAndExtensions;

namespace IBNet.DayTrade.Indicators
{
   public class HighLowCloseDividedBy3 : Indicator
   {
      public HighLowCloseDividedBy3()
         : base("HLC3") { }

      public override decimal? CalculateIndicator(FixedLengthCollection<PriceBar> priceBars)
      {
         // Avoid three additions and a division
         // by returning the close if high == low == close.
         if (priceBars[0].High == priceBars[0].Low &&
             priceBars[0].Low == priceBars[0].Close)
         {
            return priceBars[0].Close;
         }

         decimal hlc3 = (priceBars[0].High + priceBars[0].Low + priceBars[0].Close) / 3;
         return hlc3;
      }
   }
}
